package com.penghaisoft.microwms.common.service;


import com.penghaisoft.microwms.common.Constant;
import com.penghaisoft.microwms.common.page.Pagination;
import com.penghaisoft.microwms.common.page.TurnPageInfo;
import com.penghaisoft.microwms.common.dto.Resp;

/**
 * Created by zxcq0 on 2017/3/2.
 * service的基类
 */
public class BaseService<T extends Pagination> {
    /**
     * @Description: 获取翻页对象
     * @author zxcq0
     * @date 2017/3/2 16:53
     * @param
     * @return
     */
    public TurnPageInfo getTurnPageInfo(int totalCount, T obj){
        TurnPageInfo pageInfo = new TurnPageInfo();
        if (totalCount > 0){
            pageInfo.setTotalCount(totalCount);
            pageInfo.setTotalPage(totalCount%obj.getPageSize()==0?totalCount/obj.getPageSize():totalCount/obj.getPageSize()+1);
        }else {
            pageInfo.setTotalCount(0);
            pageInfo.setTotalPage(0);
        }
        return pageInfo;
    }
    /**
     * @Description: 拼装翻页信息
     * @author zxcq0
     * @date 2017/3/13 16:46
     * @param
     * @return
     */
    public void assemCondition(T obj){
       obj.setStartIndex((obj.getCurrentPage()-1)*obj.getPageSize());
    }
    
    /**
     * @Title: isLength
     * @Description: 成品 判断 型号是否是带长度的
     * @date 2019年3月26日 下午4:33:29
     * @author luoteng
     * @param modelType
     * @return Boolean   
     */
    public Boolean isProLength(String modelType) {
    	Boolean typeFlag = Constant.PRO_MODEL_STG_L.equals(modelType) || 
        		Constant.PRO_MODEL_STG_W.equals(modelType) || Constant.PRO_MODEL_STG_Z.equals(modelType)
                || Constant.PRO_MODEL_STG_DX.equals(modelType)
        		|| Constant.PRO_MODEL_GTGW_L.equals(modelType) || Constant.PRO_MODEL_GTGN_L.equals(modelType)
        		|| Constant.PRO_MODEL_GTGW_W.equals(modelType) || Constant.PRO_MODEL_GTGN_W.equals(modelType)
        		|| Constant.PRO_MODEL_BLG_L.equals(modelType) || Constant.PRO_MODEL_BLG_W.equals(modelType)
        		|| Constant.PRO_MODEL_LXF_LH.equals(modelType) || Constant.PRO_MODEL_LXF_DX.equals(modelType)
        		|| Constant.PRO_MODEL_LXF_DL.equals(modelType);
    	return typeFlag;
    }
    
    /**
     * @Title: isLength
     * @Description: 原材料 判断 型号是否是带长度的
     * @date 2019年3月26日 下午4:33:29
     * @author luoteng
     * @param modelType
     * @return Boolean   
     */
    public Boolean isRawLength(String modelType) {
    	Boolean typeFlag = Constant.MODEL_L.equals(modelType) || 
        		Constant.MODEL_W.equals(modelType) || Constant.MODEL_Z.equals(modelType)
        		|| Constant.MODEL_LDXG.equals(modelType) || Constant.MODEL_PE.equals(modelType) ;
    	return typeFlag;
    }

    protected Resp success() {
        Resp resp = new Resp();
        resp.setCode(Constant.SUCCESS);
        return resp;
    }

    protected Resp fail(String msg) {
        Resp resp = new Resp();
        resp.setCode(Constant.FAIL);
        resp.setMsg(msg);
        return resp;
    }
}
